<!DOCTYPE html>
<html>
<head>
<title>Synchronous XMLHttpRequest and caching during document load</title>
</head>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script type="text/javascript">

// Test what caching XMLHttpRequest performs when issuing sync
// requests over various verbs and with various kinds of query
// portions. Without any cache control headers.
var verbs = [ "GET", "POST" ];

var query_kinds = [
    {query: "'?random'",
     name: "constant query"},
    {query: "",
     name: "no query"},
    {query: "'?' + (Math.random() + Date.now()).toString()",
     name: "unique query string"}];

var base_url = "resources/echo-random.php";

function fetchSyncTextResponse(verb, url) {
    var xhr = new XMLHttpRequest();
    xhr.open(verb, url, false);
    xhr.send();
    return xhr.responseText;
}

function runTest() {
    for (var i = 0; i < verbs.length; i++) {
        var verb = verbs[i];
        for (var j = 0; j < query_kinds.length; j++) {
            test(function () {
                var q1 = eval(query_kinds[j].query) || "";
                var q2 = eval(query_kinds[j].query) || "";
                var result1 = fetchSyncTextResponse(verb, base_url + q1);
                var result2 = fetchSyncTextResponse(verb, base_url + q2);
                assert_false(result1 === result2);
            }, "Test repeated sync requests using verb '" + verb + "' with " + query_kinds[j].name);
        }
    }
}

test(runTest, document.title);
</script>
</body>
</html>
